﻿#include "image_push_button.h"

#include <QPainter>
#include <QMouseEvent>
#include <QDebug>

ImagePushButton::ImagePushButton(QWidget *parent)
    :QPushButton(parent)
{
    setAutoDefault(false); // 不作为自动默认的按钮（不获取默认焦点）
    setFlat(true); // 扁平化
}

ImagePushButton::~ImagePushButton()
{

}

/**
 * @brief ImagePushButton::setImageName
 *  命名: _hover, _pressed
 * @param image_name
 */
void ImagePushButton::setImageName(QString &image_name)
{
    this->m_image_name = image_name;
    setFixedSize(QPixmap(image_name).size());

    QString style_sheet = QStringLiteral("ImagePushButton{border:none;background-image:url(%1)}ImagePushButton:hover{background-image:url(%1_hover);}ImagePushButton:pressed{background-image:url(%1_pressed);}ImagePushButton:checked{background-image:url(%1_pressed);}")
                          .arg(image_name);
    setStyleSheet(style_sheet);
}
